
package com.kalvin.kvf.modules.cust.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import com.kalvin.kvf.common.controller.BaseController;
import com.kalvin.kvf.common.dto.R;
import com.kalvin.kvf.modules.cust.entity.Man;
import com.kalvin.kvf.modules.cust.service.ManService;

import java.util.List;
import java.time.LocalDateTime;

/**
 * <p>
 * 测试表 前端控制器
 * </p>
 * @since .setCreateTime(LocalDateTime.now());
 */
@RestController
@RequestMapping("cust/man")
public class ManController extends BaseController {

    @Autowired
    private ManService manService;

    @RequiresPermissions("cust:man:index")
    @GetMapping("index")
    public ModelAndView index() {
        return new ModelAndView("cust/man");
    }

    @GetMapping(value = "edit")
    public ModelAndView edit(Long id) {
        ModelAndView mv = new ModelAndView("cust/man_edit");
        Man man;
        if (id == null) {
            man = new Man();
        } else {
            man = manService.getById(id);
        }
        mv.addObject("editInfo", man);
        return mv;
    }

    @GetMapping(value = "list/data")
    public R listData(Man man) {
        Page<Man> page = manService.listManPage(man);
        return R.ok(page);
    }

    @RequiresPermissions("cust:man:add")
    @PostMapping(value = "add")
    public R add(Man man) {
        man.setCreateTime(LocalDateTime.now());
        manService.save(man);
        return R.ok();
    }

    @RequiresPermissions("cust:man:del")
    @PostMapping(value = "batchdel")
    public R batchdel(@RequestParam("ids") List<Long> ids) {
        manService.removeByIds(ids);
        return R.ok();
    }

    @RequiresPermissions("cust:man:edit")
    @PostMapping(value = "edit")
    public R edit(Man man) {
        man.setUpdateTime(LocalDateTime.now());
        manService.updateById(man);
        return R.ok();
    }

    @RequiresPermissions("cust:man:del")
    @PostMapping(value = "del/{id}")
    public R del(@PathVariable Long id) {
        manService.removeById(id);
        return R.ok();
    }

    @GetMapping(value = "get/{id}")
    public R get(@PathVariable Long id) {
        return R.ok(manService.getById(id));
    }

}

